package parser.news;

import entities.News;

import java.util.ArrayList;
import java.util.List;

/**
 * Class for getting news list from each channel
 * User: kaiser
 * Date: 7/31/13
 * Time: 9:39 PM
 */
public class ChannelParseAdapter implements NewsParser {

    /**
     * Getting news list from all channels all
     *
     * @param newsCount returned news count from each channel
     * @return
     */
    @Override
    public List<News> getNews(int newsCount) {
        List<News> newsList = new ArrayList<News>();
        List<ChannelParser> updaterList = getChannelUpdaterList();

        if (!updaterList.isEmpty()) {
            for (NewsParser updater : updaterList) {
                newsList.addAll(updater.getNews(newsCount));
            }
        }
        return newsList;
    }

    /**
     * Getting list of channels news parser objects<br/>
     *
     * @return
     */
    private List<ChannelParser> getChannelUpdaterList() {
        List<ChannelParser> updaterList = new ArrayList<ChannelParser>();

        updaterList.add(new HabrParser());
        updaterList.add(new IbmParser());
        updaterList.add(new OpennetParser());
        updaterList.add(new IxbtParser());
        updaterList.add(new ItnewsParser());

        return updaterList;
    }
}
